﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using JKF.DataModule.IDAL;

namespace JKF.DataModule.SqlServerDAL
{
    /// <summary>
    /// 数据访问类dalSMS_TEMPLEATE。
    /// </summary>
    public partial class dalSMS_TEMPLEATE : IdalSMS_TEMPLEATE
    {
        #region Fields

        private static string Fields = "st.ID,st.TEMPLEATE_NAME,st.[STATUS],st.IS_SHARE,st.CONTENT,st.SHOP_CODE,st.DATE_CREATE,st.DATE_UPDATE,su.real_name as OPERATOR";
        private static string Table = "SMS_TEMPLEATE st left join sys_user su on st.user_create=su.user_key";
        private static string FieldKey = "st.ID";
        #endregion

        /// <summary>
        /// 查询短信模版
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="isStart"></param>
        /// <param name="currentUser"></param>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        public static DataTable GetSmsTemplatePaging(string templateName, string isStart, string currentUser, int pageCurrent, int pageSize, ref  int pageCount, ref int rowCount)
        {
            var sqlBuilder = new StringBuilder();
            sqlBuilder.AppendFormat("(st.SHOP_CODE IN (SELECT SHOP_CODE FROM SYS_USER_SHOP WHERE USER_kEY='{0}') OR IS_SHARE='1')", currentUser);
            if (!string.IsNullOrEmpty(isStart)) sqlBuilder.AppendFormat(" AND st.[STATUS]='{0}'", isStart);
            if (!string.IsNullOrEmpty(templateName)) sqlBuilder.AppendFormat(" AND st.[TEMPLEATE_NAME] like'%{0}%'", templateName);
            return DataPage.GetPageInfo(Table, FieldKey, pageCurrent, pageSize, Fields, "", sqlBuilder.ToString(), ref pageCount, ref rowCount).Tables[0];
        }
    }
}
